package com.flute.framework.autoprompt;

import com.flute.tools.util.StringUtil;

public class StringToken {

	private String value;
	private static final String SPLITER = "priospliter";

	public StringToken(String text) {
		this.value = text;
	}

	public void addPriority(double priority, int pos) {
		int[] ids = StringUtil.getAllIndex(value, SPLITER);
		if (ids.length < pos) {
			value = value + SPLITER + priority;
		}
	}

	public String getText() {
		if (value.contains(SPLITER)) {
			return value.substring(0, value.indexOf(SPLITER));
		} else {
			return value;
		}
	}

	public TokenPriority getPriority() {
		TokenPriority tp = TokenPriority.getInstance();
		String[] ss = value.split(SPLITER);
		for (int i = 1; i < ss.length; i++) {
			tp.addPriority(Double.valueOf(ss[i]), i);
		}
		return tp;
	}

	public String toString() {
		return value;
	}
}
